﻿///<author>Arjen van Zanten</author>
///<datecreated>2012-03-27</datecreated>
///<summary>The entry point for the Lighting fixing. Holds static functions for fixing the lighting.</summary>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace THO7_Team8
{
    public class LightingFixer
    {
        /// <summary>
        /// Binarizes the Bitmap b, separating foreground and background, ignoring shadows and over/under-exposure as much as possible.
        /// </summary>
        /// <param name="b">Input Bitmap</param>
        public static void FixLighting(Bitmap b)
        {
            GrayscaleHistogram histogram = new GrayscaleHistogram(b);
            int threshold = Otsu.SinglePass(histogram.Array);
            BitmapProcessor.Threshold(b, threshold);
        }

        /// <summary>
        /// Returns a binarized copy of Bitmap b, separating foreground and background, ignoring shadows and over/under-exposure as much as possible.
        /// </summary>
        /// <param name="b">Input Bitmap</param>
        /// <returns>A binarized copy of Bitmap b</returns>
        public static Bitmap FixLightingToNewImage(Bitmap b)
        {
            Bitmap bmpDest = new Bitmap(b);

            FixLighting(bmpDest);

            return bmpDest;
        }
    }
}
